{include file="public/_meta" /}
<body>
<style>
    .required_b{
        color: red;
    }
</style>
<div class="wrapper">

    {include file="public/_header" /}

    <!-- Sidebar -->
    {include file="public/_menu" /}
    <!-- End Sidebar -->

    <div class="main-panel">

        <div class="content">
            <div class="page-inner">

                <!-- 面包屑 -->
                {include file="public/_page_header" /}

                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="d-flex align-items-center">
                                    <h4 class="card-title">城市准入</h4>

                                    <button class="btn btn-primary btn-round ml-auto" data-toggle="modal" data-target="#addRowModal" onClick="add_item(0)">
                                        <i class="fa fa-plus"></i>
                                        添加
                                    </button>

                                </div>

                                <form class="row">

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <select class="form-control" name="status">
                                                <option value="">全部状态</option>
                                                <option value="1" {if condition="1 eq $status"}selected{/if}>启用</option>
                                                <option value="0" {if condition="2 eq $status"}selected{/if}>禁用</option>
                                            </select>
                                        </div>
                                    </div>



                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="acc_name" value="{$acc_name}" placeholder="请输入账户名称">
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="cityname" value="{$cityname}" placeholder="请输入城市">
                                        </div>
                                    </div>



                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <button type="submit" class="btn btn-primary">查询</button>
                                            <a href="{:url('account_city_in/index')}" class="btn btn-info" style="color: white;position: absolute;left: 110px;">重置</a>
                                        </div>
                                    </div>

                                </form>

                            </div>


                            <div class="card-body">
                                <!-- Modal -->
                                <div class="modal fade" id="addRowModal" tabindex="-1" role="dialog" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header no-bd">
                                                <h5 class="modal-title">
                                                    <span class="fw-mediumbold">添加</span>

                                                </h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <form id="form-modal">
                                                    <div class="row">

                                                        <!--<div class="form-group form-inline col-md-12" id="push_type2">
                                                            <label class="col-md-3 col-form-label">账户</label>
                                                            <div class="col-md-8 p-0" id="accSelect">

                                                            </div>
                                                        </div>-->

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="acc_id" class="col-md-3 col-form-label">账户</label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="acc_id" id="acc_id">
                                                                    <option value="0">--请选择--</option>
                                                                    {volist name="account" id="vo"}
                                                                    <option value="{$vo.id}">{$vo.acc_name}【{$vo.adv_id}】</option>
                                                                    {/volist}

                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="accept_limit_num" class="col-md-3 col-form-label">每日接收线索数</label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="accept_limit_num" name="accept_limit_num" placeholder="每日接收线索数">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="content" class="col-md-3 col-form-label">城市(市级)<br>(一个城市一行)</label>
                                                            <div class="col-md-8 p-0">
                                                                <textarea id="content" name="content" class="form-control input-full" style="height: 500px!important"></textarea>
                                                            </div>
                                                        </div>

                                                    </div>
                                                    <div class="modal-footer no-bd">
                                                        <input type="hidden" id="id" name="id" value="">
                                                        <button type="submit" id="addRowButton" class="btn btn-primary">保存</button>
                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                                                    </div>
                                                </form>
                                            </div>

                                        </div>
                                    </div>
                                </div>


                                <div class="table-responsive">
                                    <table id="add-row" class="display table table-striped table-hover" >
                                        <thead>
                                        <tr>


                                            <th>账户</th>

                                            <th>城市</th>
                                            <th>每日接收数</th>

                                            <th>创建时间</th>
                                            <th>是否启用</th>

                                            <th style="width: 10%">操作</th>


                                        </tr>
                                        </thead>

                                        <tbody>

                                        {volist name="infos" id="vo"}
                                        <tr>


                                            <td>{$vo.acc_name}</td>

                                            <td>{$vo.city}</td>

                                            <td class="text-c listorder"><input style="text-align:center;" attr-id="{$vo.id}" name="listorder" value="{$vo.accept_limit_num}"></td>

                                            <td>{$vo.create_time}
<!--                                                修改时间：{$vo.update_time}-->
                                            </td>
<!--                                            <td>{$vo.update_time}</td>-->
                                            <td>{$vo.status|getStatus}</td>
                                            <td>
                                                <div class="form-button-action">

                                                    {if condition="$vo.status eq 1"}

                                                    <button type="button" data-toggle="tooltip" title="" onClick="admin_stop(this,'{$vo.id}')" class="btn btn-link btn-warning" data-original-title="停用">
                                                        <i class="fa fa-toggle-on"></i>停用
                                                    </button>


                                                    {else/}

                                                    <button type="button" data-toggle="tooltip" title="" onClick="admin_start(this,'{$vo.id}')" class="btn btn-link btn-success" data-original-title="启用">
                                                        <i class="fa fa-toggle-off"></i>启用
                                                    </button>
                                                    {/if}

                                                    <button type="button" title="编辑" class="btn btn-link btn-primary btn-lg" data-toggle="modal" data-target="#addRowModal" onClick="edit_item('{$vo.id}')">
                                                        <i class="fa fa-edit"></i>编辑该账号城市
                                                    </button>


                                                    <button type="button" data-toggle="tooltip" onClick="admin_del(this,'{$vo.id}')" title="" class="btn btn-link btn-danger" data-original-title="删除">
                                                        <i class="fa fa-times"></i>删除该账号全部城市
                                                    </button>

                                                </div>

                                            </td>
                                        </tr>
                                        {/volist}

                                        </tbody>
                                    </table>

                                    <!-- 分页 (调取通用方法)-->
                                     <div class="layui-box layui-laypage layui-laypage-molv">{:pagination($infos)}</div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>

        {include file="public/_footer" /}


    </div>



</div>

{include file="public/_js" /}

</body>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    var SCOPE = {
        'edit_accept_limit_num':"{:url('accountCityIn/edit_accept_limit_num')}",
        'status_url':"{:url('accountCityIn/cityStatus')}",
        'delete_url':"{:url('accountCityIn/delete')}",

        'item_url':"{:url('accountCityIn/edit')}",
        'add_url':"{:url('accountCityIn/citySave')}",
    };

    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal").validate({

            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.add_url;
                if(commitStatus==true){
                    return false;
                }

                if($("#content").val() == 0)
                {
                    layer.msg('请输入城市',{icon:2,time:2000});
                    return false;
                }

                if($("input[name='acc_id']:selected").val() == 0)
                {
                    layer.msg('请选择账户',{icon:2,time:2000});
                    return false;
                }

                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function (data) {
                        if (data.code == 1001) {
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function () {
                                parent.location.reload();
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 2000});
                        }
                    },
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                        layer.msg(errorThrown, {icon: 2, time: 2000});
                    }
                });

            }
        });

    });

    function add_item(id) {
        document.getElementById('form-modal').reset();
        $("input[name='id']").val(id);

    }

    function edit_item(id) {
        document.getElementById('form-modal').reset();
        $.ajax({
            type: 'GET',
            url: SCOPE.item_url,
            dataType: 'json',
            data: {id:id},
            success: function(res){

                if(res.code == 1001){
                    $("#id").val(res.data.id);
                    $("#content").val(res.data.content);
                    $("#accept_limit_num").val(res.data.accept_limit_num);
                    $("#acc_id").val(res.data.acc_id);

                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }

    /*删除*/
    function admin_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: SCOPE.delete_url,
                dataType: 'json',
                data: {id:id},
                success: function(data){
                    if(data.code == 1001){
                        layer.msg(data.msg,{icon:1,time:2000});
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }

                },
                error:function(data) {
                    layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
                }
            });
        });
    }


    /*机构-停用*/
    function admin_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            var url = SCOPE.status_url;
            $.post(url,{status:0,id:id},function(data){
                if(data.code == 1001){
                    layer.msg('已停用!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }

            });


        });
    }

    /*机构-启用*/
    function admin_start(obj,id){
        layer.confirm('确认要启用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……

            var url = SCOPE.status_url;
            $.post(url,{status:1,id:id},function(data){
                if(data.code == 1001){

                    layer.msg('已启用!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }
            });
        });
    }


    $(".listorder input").blur(function(){
        // 编写抛送的逻辑
        var id = $(this).attr('attr-id'); //获取主键id
        var listorder = $(this).val(); //获取排序的值
        var postData = {
            'id':id,
            'accept_limit_num':listorder
        };
        var url = SCOPE.edit_accept_limit_num; //抛送地址
        $.post(url,postData,function(result){
            if(result.code == 1001){
                layer.msg('编辑成功!', {icon: 1,time: 1000}, function(){
                    window.location.reload();
                });
            }else{
                layer.msg(result.msg,{icon:2,time:2000});
            }
        },"json");
    });


</script>

<script src="__STATIC__/layui/layui.js"></script>
<script>
    layui.use(['form'], function() {
        var form = layui.form;
    });

</script>

</html>




























